<template>
	<view class="page">
		<u-sticky bg-color="#fff">
			<view :style="{ padding: '20rpx'}">
				<u-input v-model="search" placeholder="搜索你感兴趣的内容" suffix-icon="search" clearable
					suffix-icon-style="color: #909399" shape="circle" border="none" font-size="13px"
					@confirm="handleSearch" :custom-style="{
		      background: '#F4F4F4',
		      padding: '6px 12px',
		      boxShadow: '0 0 20rpx rgba(186, 186, 186, 0.1)',
		    }" />
			</view>
			<view class="chooseCup"
				style="color: #000 !important;margin: 10rpx 0 10rpx !important;display: flex;justify-content: space-around;">
				<view class="" style="display: flex;align-items: center;">
					<vvSelect :list="typeList" label="name" valueKey="id" placeholder-style="color: #F5F5F5"
						:placeholder="placeholder1" ref="vvSelect" @change="tabChange"></vvSelect>
					<view class="" style="margin-left: 8rpx;">
						<u-icon name="arrow-down" size="16"></u-icon>
					</view>
				</view>
				<view class="" style="display: flex;align-items: center;">
					<vvSelect :list="orderList" label="name" valueKey="id" placeholder-style="color: #F5F5F5"
						:placeholder="placeholder2" ref="vvSelect" @change="orderChange"></vvSelect>
					<view class="" style="margin-left: 8rpx;">
						<u-icon name="arrow-down" size="16"></u-icon>
					</view>
				</view>
			</view>

		</u-sticky>

		<view class="body">
			<view class="line"></view>
			<view class="item" v-for="(item,index) in dataList" :key="index" v-if="dataList.length!=0"
				@tap.stop="handleDetail(item)">
				<view class="top1">
					<image :src="$imageOss(item.image)" mode="widthFix" style="" class="image"></image>
					<view class="top">
						{{item.title}}
					</view>
					<view class="bot">
						<text class="bot1">申报地区：{{item.address}} </text>
					</view>
					<view class="bot">
						<view class="bot2"> {{item.createtime}}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
	</view>
</template>
<script>
	import {
		heritageList,
		heritageCategory
	} from "@/request/homeApi.js";
	import vvSelect from '@/components/vv-select/index.vue'
	export default {
		components: {
			vvSelect
		},
		data() {
			return {
				typeList: [],
				orderList: [{
					id: '',
					name: '最新'
				}, {
					id: 'like',
					name: '最热'
				}],
				placeholder1: '全部类型',
				placeholder2: '最新',
				dataList: [],
				last_page: 1,
				search: '',
				page: 1,
				status: "nomore", // 加载状态
				heritage_category_id: '',
				type: ''
			};
		},
		onReachBottom() {
			let that = this
			if (that.page < that.last_page) {
				that.page = that.page + 1
				that.getList()
			}
		},
		watch: {
			search(val) {
				if (!val) {
					this.handleSearch()
				}
			}
		},
		onLoad(e) {
			this.dataList = []
			if (e) {
				this.search = e.title ? e.title : ''
			}
			this.getTypeList();
			this.getList();
		},
		methods: {
			// 类型切换
			tabChange(e) {
				this.heritage_category_id = e
				this.dataList = []
				this.getList()
			},

			// 排序
			orderChange(e) {
				this.type = e
				this.dataList = []
				this.getList()
			},
			// 获取品非遗类型
			getTypeList() {
				let that = this
				heritageCategory().then((res) => {
					res.data.unshift({
						name: "全部类型",
						id: ""
					});
					that.typeList = res.data;
				});
			},
			// 获取品非遗列表
			getList() {
				this.status = "loading";
				let that = this
				heritageList({
					heritage_category_id: that.heritage_category_id,
					page: that.page,
					limit: 10,
					title: that.search,
					type: this.type,
					recommend: ''
				}).then(res => {
					that.dataList = that.dataList.concat(res.data.list)
					that.last_page = Math.ceil(res.data.count / res.data.list.length)
					res.data.count == 0 ? that.status = 'nomore' : that.status = ''
				})
			},
			// 搜索
			handleSearch(e) {
				this.heritage_category_id = ''
				this.page = 1;
				this.search = e ? e : ''
				this.dataList = []
				this.getList();
			},

			// 查看详情
			handleDetail(val) {
				uni.navigateTo({
					url: `/pages/home/heritageDetails?id=${val.id}`,
				});
			},
		},
	};
</script>
<style lang="scss" scoped>
	.page {
		.chooseCup {
			margin-right: 8rpx !important;
			font-size: 28rpx;

			image {
				width: 20rpx !important;
				height: 12rpx !important;
				margin: 14rpx;
			}
		}

		.body {
			padding: 10rpx 20rpx;
			display: flex;
			flex-direction: column;

			.line {
				width: 100%;
				height: 5rpx;
				background: #F4F4F4;
			}

			.item {
				padding: 10rpx;
				background-color: #fff;
				margin-bottom: 20rpx;

				.top1 {
					display: flex;
					flex-direction: column;

					.image {
						height: 340rpx !important;
						width: 100%;
						border-radius: 10rpx;
					}

					.top {
						color: #313131;
						font-family: PingFang SC;
						font-size: 30rpx;
						font-style: normal;
						font-weight: 400;
						line-height: normal;
						margin-top: 14rpx;
					}

					.bot {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						margin-top: 10rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;

						.bot1 {
							color: #909090;
							font-family: PingFang SC;
							font-size: 24rpx;
							font-style: normal;
							font-weight: 400;
							line-height: normal;
						}

						.bot2 {
							color: #909090;
							font-family: PingFang SC;
							font-size: 24rpx;
							font-style: normal;
							font-weight: 400;
							line-height: normal;
						}
					}
				}

				.other {
					display: flex;
					justify-content: space-between;
					margin-top: 20rpx;
					flex-direction: row-reverse;

					.left {
						width: 160rpx;
						height: 122rpx;
						margin-left: 20rpx;

						.image {
							border-radius: 8rpx;
							width: 100%;
							height: 100%;
						}
					}

					.right {
						flex: 1;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.top {}

						.bot {
							display: flex;
							flex-direction: column;
							justify-content: space-between;

							.bot1 {
								color: #909090;
								font-family: PingFang SC;
								font-size: 24rpx;
								font-style: normal;
								font-weight: 400;
								line-height: normal;
							}

							.bot2 {
								color: #313131;
								font-family: PingFang SC;
								font-size: 20rpx;
								font-style: normal;
								font-weight: 400;
								line-height: normal;
								margin-top: 10rpx;
							}
						}
					}
				}
			}

			.f-bottom {
				font-weight: 600;
				font-size: 28rpx;
				color: $active-color;
				margin-left: 20rpx;

				text:nth-child(2) {
					font-size: 24rpx;
				}

				text:last-child {
					font-size: 40rpx;
				}
			}
		}

		.tabBox {
			display: flex;
			justify-content: space-evenly;
			width: 100%;
			padding: 10rpx 0 0;
			box-sizing: border-box;
			text-align: center;
			font-size: 30rpx;

			/deep/.u-scroll-list {
				width: 100%;
				padding-bottom: 0;
			}

			.leftIcon {
				width: 120rpx;
				height: 3rpx;
				margin: 14rpx auto;
			}

			.navItem {
				width: 160rpx;
				text-align: center !important;
				overflow: hidden;
			}
		}
	}
</style>